using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;

namespace MJB.UI.ContentEditor.Windows
{
    /// <summary>
    /// Interaction logic for SettingsWindow.xaml
    /// </summary>
    public partial class SettingsWindow : System.Windows.Window
    {
        /// <summary>
        /// These are the editor settings.
        /// </summary>
        private EditorSettings mSettings;

        /// <summary>
        /// Creates the setup window.
        /// </summary>
        public SettingsWindow()
        {
            InitializeComponent();

            mSettings = new EditorSettings();
            mSettings.LoadFromRegistry();
            this.DataContext = mSettings;
            this.mPasswordTextBox.Password = mSettings.Password;

        }

        /// <summary>
        /// Called when the browse button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void OnXMLDirectoryBrowseButtonClicked(object sender, EventArgs args)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            if(mSettings.XmlDirectory.Length > 0)
                folderDialog.SelectedPath = mSettings.XmlDirectory;

            DialogResult result = folderDialog.ShowDialog();
            if(result == System.Windows.Forms.DialogResult.OK)
                mSettings.XmlDirectory = folderDialog.SelectedPath;

        }

        /// <summary>
        /// Called when the OK button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void OnOKButtonClicked(object sender, EventArgs args)
        {
            mSettings.Password = mPasswordTextBox.Password;
            mSettings.SaveToRegistry();
            this.Close();
        }

        /// <summary>
        /// Called when the cancel button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void OnCancelButtonClicked(object sender, EventArgs args)
        {
            this.Close();
        }

    }

}